Dynomotion

Group: DynoMotion Message: 6812 From: himykabibble Date: 2/24/2013
Subject: KMotion_dotNet Initialization Sequence
Tom,

I'm doing some more cleanup on my app, putting in more error handling, and a few other things. Right now, I'm cleaning up the handling of disconnects, which has uncovered some "issues". I find my initialization sequence works fine when the board is connected at the time the app starts up, but doesn't work so well if the board is plugged in after the app starts, making me wonder if my initialization sequence is less than ideal. Here's what I'm doing:

Create KM_Controller object
Hook in my message handlers (console, error, interpreter)
Initialize the KM_IO dictionary from my XML config file
Initialize the KM_Axis dictionary from my XML config file
Do a "Version" call, to make sure the board is responding
Initialize critical I/O states (spindle, coolant, enables, etc.)
Initialize my Persist Vars from my XML config file
Initialize CoordMotion axis parameters from my XML config file
Initialize CoordMotion and Interpreter parameters and callbacks
Initialize MCode actions from my XML config file
Start my threads for Init, Pendant, and Spindle control

Does this seem reasonable? Any obvious problems?

One thing that surprised me is that initializing the MCode actions throws exceptions if the board is not connected. I'm curious why that is, given that MCodes are processed by the interpreter, which is on the PC side.

Is there any way to know which dotNet functions are dependant on the board being connected?

Regards,
Ray L.
Group: DynoMotion Message: 6813 From: himykabibble Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Perhaps a bug?

String s = KMController.WriteLineReadLine("Echo TEST");

always returns an empty string....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy1964@...> wrote:
>
> Tom,
>
> I'm doing some more cleanup on my app, putting in more error handling, and a few other things. Right now, I'm cleaning up the handling of disconnects, which has uncovered some "issues". I find my initialization sequence works fine when the board is connected at the time the app starts up, but doesn't work so well if the board is plugged in after the app starts, making me wonder if my initialization sequence is less than ideal. Here's what I'm doing:
>
> Create KM_Controller object
> Hook in my message handlers (console, error, interpreter)
> Initialize the KM_IO dictionary from my XML config file
> Initialize the KM_Axis dictionary from my XML config file
> Do a "Version" call, to make sure the board is responding
> Initialize critical I/O states (spindle, coolant, enables, etc.)
> Initialize my Persist Vars from my XML config file
> Initialize CoordMotion axis parameters from my XML config file
> Initialize CoordMotion and Interpreter parameters and callbacks
> Initialize MCode actions from my XML config file
> Start my threads for Init, Pendant, and Spindle control
>
> Does this seem reasonable? Any obvious problems?
>
> One thing that surprised me is that initializing the MCode actions throws exceptions if the board is not connected. I'm curious why that is, given that MCodes are processed by the interpreter, which is on the PC side.
>
> Is there any way to know which dotNet functions are dependant on the board being connected?
>
> Regards,
> Ray L.
>
Group: DynoMotion Message: 6814 From: himykabibble Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Tom,

I'm finding that after allowing my app to come up normally, then disconnecting, and re-connecting the board, it goes into a WriteLineReadLine call, and never returns. It disappears into:

KM_dotnet_Interop_WriteLineReadLine(_InstanceHandle, command, ref response);

in KMController.cs, and never returns, nor does it even throw an exception. I can't seem to step into that method. I have the reference in my project pointing to the Debug build of KMotion_dotNet.dll. Is there something more I need to do to be able to step into the DLLs? I haven't tried to do that in quite some time.

Regards,
Ray L.


--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy1964@...> wrote:
>
> Perhaps a bug?
>
> String s = KMController.WriteLineReadLine("Echo TEST");
>
> always returns an empty string....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy1964@> wrote:
> >
> > Tom,
> >
> > I'm doing some more cleanup on my app, putting in more error handling, and a few other things. Right now, I'm cleaning up the handling of disconnects, which has uncovered some "issues". I find my initialization sequence works fine when the board is connected at the time the app starts up, but doesn't work so well if the board is plugged in after the app starts, making me wonder if my initialization sequence is less than ideal. Here's what I'm doing:
> >
> > Create KM_Controller object
> > Hook in my message handlers (console, error, interpreter)
> > Initialize the KM_IO dictionary from my XML config file
> > Initialize the KM_Axis dictionary from my XML config file
> > Do a "Version" call, to make sure the board is responding
> > Initialize critical I/O states (spindle, coolant, enables, etc.)
> > Initialize my Persist Vars from my XML config file
> > Initialize CoordMotion axis parameters from my XML config file
> > Initialize CoordMotion and Interpreter parameters and callbacks
> > Initialize MCode actions from my XML config file
> > Start my threads for Init, Pendant, and Spindle control
> >
> > Does this seem reasonable? Any obvious problems?
> >
> > One thing that surprised me is that initializing the MCode actions throws exceptions if the board is not connected. I'm curious why that is, given that MCodes are processed by the interpreter, which is on the PC side.
> >
> > Is there any way to know which dotNet functions are dependant on the board being connected?
> >
> > Regards,
> > Ray L.
> >
>
Group: DynoMotion Message: 6815 From: Tom Kerekes Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Hi Ray,

I tried:

            try
            {
                String s = KM.WriteLineReadLine("Echo TEST");
            }
            catch (DMException ex) // in case disconnect in the middle of reading status
            {
                MessageBox.Show(ex.InnerException.Message);
            }

And I get an Exception when a board is not connected and also a message callback.  Not sure why you don't.  There is a "_ThrowExceptions" property.

To debug into the DLLs you need to set Enable Unmanaged Code Debugging in the properties.

Sounds like you have another issue with the Token not being released.

Regards
TK


Group: DynoMotion Message: 6816 From: himykabibble Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Tom,

Thanks. That's a little baffling.... Here's the code in question:

try
{
String s = KMController.WriteLineReadLine("Echo TEST");
if (s.Equals("TEST"))
ret = true;
}
catch (Exception e)
{
throw new Exception("Unable to connect to board");
}

When I single-step with the board connected, it executes the "if", but s is always an empty string. With the board not connected, the WriteLineReadLine call never returns.

I'll turn on unmanaged code debugging and see what I find.

What I've done is added traps for exceptions to all of my methods that communicate with the board, most of which simply ignore the exception. A few key ones, like GetMainStatus() call a method that displays an error dialog, giving the user the option of either re-trying, or quitting. If the user opts to re-try, then it attempts to re-initialize the board. If successful, then, in theory, we're back in business. If not, it simply returns to the trap, and re-displays the dialog. That all seem to work very reliably, except the app does not return to full functionality after the connection is restores.

There is definitely a threading issue going on. I've found that if I replace the above with a call to "Version", checking the result starts with "KFLOP", it runs ok, but, after re-connecting, the timer handler that does the display updates is no longer getting called. I suspect when I get to the bottom of that, I'll be in business.

I *think* this is the last significant issue I have with this app, and it's a very minor one for me, since the board has never disconnected in use. Everything else is working flawlessly.

Regards,
Ray L.


--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>
> I tried:
>
>             try
>             {
>                 String s = KM.WriteLineReadLine("Echo TEST");
>             }
>             catch (DMException ex) // in case disconnect in the middle of reading status
>             {
>                 MessageBox.Show(ex.InnerException.Message);
>             }
>
>
> And I get an Exception when a board is not connected and also a message callback.  Not sure why you don't.  There is a "_ThrowExceptions" property.
>
>
> To debug into the DLLs you need to set Enable Unmanaged Code Debugging in the properties.
>
> Sounds like you have another issue with the Token not being released.
>
>
> Regards
> TK
>
>
>
>
>
> ________________________________
> From: himykabibble <jagboy1964@...>
> To: DynoMotion@yahoogroups.com
> Sent: Monday, February 25, 2013 6:59 AM
> Subject: [DynoMotion] Re: KMotion_dotNet Initialization Sequence
>
>
>  
> Tom,
>
> I'm finding that after allowing my app to come up normally, then disconnecting, and re-connecting the board, it goes into a WriteLineReadLine call, and never returns. It disappears into:
>
> KM_dotnet_Interop_WriteLineReadLine(_InstanceHandle, command, ref response);
>
> in KMController.cs, and never returns, nor does it even throw an exception. I can't seem to step into that method. I have the reference in my project pointing to the Debug build of KMotion_dotNet.dll. Is there something more I need to do to be able to step into the DLLs? I haven't tried to do that in quite some time.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" wrote:
> >
> > Perhaps a bug?
> >
> > String s = KMController.WriteLineReadLine("Echo TEST");
> >
> > always returns an empty string....
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" wrote:
> > >
> > > Tom,
> > >
> > > I'm doing some more cleanup on my app, putting in more error handling, and a few other things. Right now, I'm cleaning up the handling of disconnects, which has uncovered some "issues". I find my initialization sequence works fine when the board is connected at the time the app starts up, but doesn't work so well if the board is plugged in after the app starts, making me wonder if my initialization sequence is less than ideal. Here's what I'm doing:
> > >
> > > Create KM_Controller object
> > > Hook in my message handlers (console, error, interpreter)
> > > Initialize the KM_IO dictionary from my XML config file
> > > Initialize the KM_Axis dictionary from my XML config file
> > > Do a "Version" call, to make sure the board is responding
> > > Initialize critical I/O states (spindle, coolant, enables, etc.)
> > > Initialize my Persist Vars from my XML config file
> > > Initialize CoordMotion axis parameters from my XML config file
> > > Initialize CoordMotion and Interpreter parameters and callbacks
> > > Initialize MCode actions from my XML config file
> > > Start my threads for Init, Pendant, and Spindle control
> > >
> > > Does this seem reasonable? Any obvious problems?
> > >
> > > One thing that surprised me is that initializing the MCode actions throws exceptions if the board is not connected. I'm curious why that is, given that MCodes are processed by the interpreter, which is on the PC side.
> > >
> > > Is there any way to know which dotNet functions are dependant on the board being connected?
> > >
> > > Regards,
> > > Ray L.
> > >
> >
>
Group: DynoMotion Message: 6817 From: Tom Kerekes Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Hi Ray,

I'm not looking at the code right now, but I believe ECHO sends the string to the Console much like a printf from a KFLOP Thread rather than as a Command Response.  That probably explains the different behavior of VERSION vs ECHO.

Regards
TK


Group: DynoMotion Message: 6818 From: himykabibble Date: 2/25/2013
Subject: Re: KMotion_dotNet Initialization Sequence
Tom,

Ah! That makes sense.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>
> I'm not looking at the code right now, but I believe ECHO sends the string to the Console much like a printf from a KFLOP Thread rather than as a Command Response.  That probably explains the different behavior of VERSION vs ECHO.
>
> Regards
> TK
>
>
>
>
> ________________________________
> From: himykabibble <jagboy1964@...>
> To: DynoMotion@yahoogroups.com
> Sent: Monday, February 25, 2013 8:48 AM
> Subject: [DynoMotion] Re: KMotion_dotNet Initialization Sequence
>
>
>  
> Tom,
>
> Thanks. That's a little baffling.... Here's the code in question:
>
> try
> {
> String s = KMController.WriteLineReadLine("Echo TEST");
> if (s.Equals("TEST"))
> ret = true;
> }
> catch (Exception e)
> {
> throw new Exception("Unable to connect to board");
> }
>
> When I single-step with the board connected, it executes the "if", but s is always an empty string. With the board not connected, the WriteLineReadLine call never returns.
>
> I'll turn on unmanaged code debugging and see what I find.
>
> What I've done is added traps for exceptions to all of my methods that communicate with the board, most of which simply ignore the exception. A few key ones, like GetMainStatus() call a method that displays an error dialog, giving the user the option of either re-trying, or quitting. If the user opts to re-try, then it attempts to re-initialize the board. If successful, then, in theory, we're back in business. If not, it simply returns to the trap, and re-displays the dialog. That all seem to work very reliably, except the app does not return to full functionality after the connection is restores.
>
> There is definitely a threading issue going on. I've found that if I replace the above with a call to "Version", checking the result starts with "KFLOP", it runs ok, but, after re-connecting, the timer handler that does the display updates is no longer getting called. I suspect when I get to the bottom of that, I'll be in business.
>
> I *think* this is the last significant issue I have with this app, and it's a very minor one for me, since the board has never disconnected in use. Everything else is working flawlessly.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes wrote:
> >
> > Hi Ray,
> >
> > I tried:
> >
> >             try
> >             {
> >                 String s = KM.WriteLineReadLine("Echo TEST");
> >             }
> >             catch (DMException ex) // in case disconnect in the middle of reading status
> >             {
> >                 MessageBox.Show(ex.InnerException.Message);
> >             }
> >
> >
> > And I get an Exception when a board is not connected and also a message callback.  Not sure why you don't.  There is a "_ThrowExceptions" property.
> >
> >
> > To debug into the DLLs you need to set Enable Unmanaged Code Debugging in the properties.
> >
> > Sounds like you have another issue with the Token not being released.
> >
> >
> > Regards
> > TK
> >
> >
> >
> >
> >
> > ________________________________
> > From: himykabibble
> > To: DynoMotion@yahoogroups.com
> > Sent: Monday, February 25, 2013 6:59 AM
> > Subject: [DynoMotion] Re: KMotion_dotNet Initialization Sequence
> >
> >
> >  
> > Tom,
> >
> > I'm finding that after allowing my app to come up normally, then disconnecting, and re-connecting the board, it goes into a WriteLineReadLine call, and never returns. It disappears into:
> >
> > KM_dotnet_Interop_WriteLineReadLine(_InstanceHandle, command, ref response);
> >
> > in KMController.cs, and never returns, nor does it even throw an exception. I can't seem to step into that method. I have the reference in my project pointing to the Debug build of KMotion_dotNet.dll. Is there something more I need to do to be able to step into the DLLs? I haven't tried to do that in quite some time.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" wrote:
> > >
> > > Perhaps a bug?
> > >
> > > String s = KMController.WriteLineReadLine("Echo TEST");
> > >
> > > always returns an empty string....
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" wrote:
> > > >
> > > > Tom,
> > > >
> > > > I'm doing some more cleanup on my app, putting in more error handling, and a few other things. Right now, I'm cleaning up the handling of disconnects, which has uncovered some "issues". I find my initialization sequence works fine when the board is connected at the time the app starts up, but doesn't work so well if the board is plugged in after the app starts, making me wonder if my initialization sequence is less than ideal. Here's what I'm doing:
> > > >
> > > > Create KM_Controller object
> > > > Hook in my message handlers (console, error, interpreter)
> > > > Initialize the KM_IO dictionary from my XML config file
> > > > Initialize the KM_Axis dictionary from my XML config file
> > > > Do a "Version" call, to make sure the board is responding
> > > > Initialize critical I/O states (spindle, coolant, enables, etc.)
> > > > Initialize my Persist Vars from my XML config file
> > > > Initialize CoordMotion axis parameters from my XML config file
> > > > Initialize CoordMotion and Interpreter parameters and callbacks
> > > > Initialize MCode actions from my XML config file
> > > > Start my threads for Init, Pendant, and Spindle control
> > > >
> > > > Does this seem reasonable? Any obvious problems?
> > > >
> > > > One thing that surprised me is that initializing the MCode actions throws exceptions if the board is not connected. I'm curious why that is, given that MCodes are processed by the interpreter, which is on the PC side.
> > > >
> > > > Is there any way to know which dotNet functions are dependant on the board being connected?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > >
> >
>